package com.deanlib.cabinet.data;

import android.content.Context;

import com.deanlib.cabinet.data.db.DaoMaster;
import com.deanlib.cabinet.data.db.DaoSession;
import com.deanlib.plantern.Plantern;

/**
 * Created by Dean on 2022/8/30
 */
public class AppDatabase {

    private static DaoSession daoSession;

    public static DaoSession getDaoSession(){
        if (daoSession == null){
            synchronized (AppDatabase.class){
                if (daoSession == null){
                    AppOpenHelper appOpenHelper = new AppOpenHelper(Plantern.getAppContext(), "cabinet.db");
                    DaoMaster daoMaster = new DaoMaster(appOpenHelper.getWritableDatabase());
                    daoSession = daoMaster.newSession();
                }
            }
        }
        return daoSession;
    }

    static class AppOpenHelper extends DaoMaster.OpenHelper{

        public AppOpenHelper(Context context, String name) {
            super(context, name);
        }
    }
}
